<template>
  <el-config-provider :locale="currentLocale">
    <router-view />
    <ReDialog />
  </el-config-provider>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { ElConfigProvider } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { ReDialog } from "@/components/ReDialog";
import { useNav } from "@/layout/hooks/useNav";
import { logout, test } from "./api/user";
export default defineComponent({
  name: "app",
  components: {
    [ElConfigProvider.name]: ElConfigProvider,
    ReDialog
  },
  computed: {
    currentLocale() {
      return zhCn;
    },
    userId() {
      return useNav().userId
    }
  },
  mounted() {
    // 注册 beforeunload 事件
    window.addEventListener('beforeunload', this.handleBeforeUnload);
  },
  // beforeDestroy() {
  //   // 清理事件监听
  //   window.removeEventListener('beforeunload', this.handleBeforeUnload);
  // },
  methods: {
    handleBeforeUnload(event) {
      test()
      // if (this.userId.value) {
      logout({ userid: this.userId.value })
      // }
      test()
    }
  }
});
</script>
